<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>添加节假日-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="/holiday/static/css/font.css">
		<link rel="stylesheet" href="/holiday/static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

	<body>
		<div class="weadmin-body">
			<form class="layui-form">
				<div class="layui-form-item">
					<label for="holidayDate" class="layui-form-label">
						<span class="we-red">*</span>日期
					</label>
					<div class="layui-input-inline">
						<input lay-verify="required|date" class="layui-input" placeholder="日期" name="holidayDate" id="holidayDate" autocomplete="off" />
					</div>
				</div>
				<div class="layui-form-item">
				    <label for="holiday" class="layui-form-label">
						<span class="we-red">*</span>是否放假
					</label>
				    <div class="layui-input-block" id="holiday">
				      <input lay-verify="required" type="radio" name="holiday" value=true title="放假">
				      <input lay-verify="required" id="ss" type="radio" name="holiday" value=false title="上班">
				    </div>
				</div>
				<div class="layui-form-item">
					<label for="holidayName" class="layui-form-label">
		                <span class="we-red">*</span>节假日名字
		            </label>
					<div class="layui-input-inline">
						<input lay-verify="required" type="text" id="holidayName" name="holidayName" autocomplete="off" class="layui-input">
					</div>

				</div>
				<div class="layui-form-item">
					<label for="holidayType" class="layui-form-label">
                  		<span class="we-red">*</span>日期类型
              		</label>
					<div class="layui-input-inline">
						<select id="holidayType" name="holidayType" lay-verify="required">
							<option value="2">节假日</option>
							<option value="0">正常上班</option>
							<option value="1">周末休息</option>
							<option value="3">调休上班</option>
						  </select>
					</div>
				</div>
				<div class="layui-form-item">
					<label for="L_repass" class="layui-form-label">
              </label>
					<button class="layui-btn" lay-filter="add" lay-submit="">确定</button>
				</div>
			</form>
		</div>
		<script src="/holiday/static/lib/layui/layui.js" charset="utf-8"></script>
		
		<script>
			function getQueryString(name) {
				var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r!=null)return  unescape(r[2]); return null;
			}
			layui.extend({
				admin: '/holiday/static/js/admin'
			});
			layui.use(['form', 'jquery','util','admin', 'layer', 'laydate'], function() {
				var form = layui.form,
					$ = layui.jquery,
					util = layui.util,
					admin = layui.admin,
					layer = layui.layer
					laydate = layui.laydate;
				
				laydate.render({
					elem: '#holidayDate'
				})
				var id = parseInt(getQueryString("id") != null ? getQueryString("id"):0)
				$.get("/holiday/holiDate/id/" + id, function(res) {
					console.log(res)
					$("#holidayDate").val(res.data.dateTime.substring(0,10))
					var inputName = res.data.holiday ? "input[name='holiday'][title='放假']" : "input[name='holiday'][title='上班']"
					$(inputName).attr("checked",true)
					$("#holidayName").val(res.data.holidayName)
					$("option[value="+res.data.holidayType +"]").attr("selected", true)
					form.render();
				})

				//自定义验证规则
				form.verify({
					holidayType: function(value) {
						if(value.length < 5) {
							return '昵称至少得5个字符啊';
						}
					},
					pass: [/(.+){6,12}$/, '密码必须6到12位'],
					repass: function(value) {
						if($('#L_pass').val() != $('#L_repass').val()) {
							return '两次密码不一致';
						}
					}
				});
				//失去焦点时判断值为空不验证，一旦填写必须验证
				$('input[name="email"]').blur(function(){
					//这里是失去焦点时的事件
					if($('input[name="email"]').val()){
						$('input[name="email"]').attr('lay-verify','email');
					}else{
						$('input[name="email"]').removeAttr('lay-verify');
					}
				});

				//监听提交
				form.on('submit(add)', function(data) {
					//console.log(data.field);
					var formData = data.field;
					//console.log(f.username);
					//console.log(f.sex);				
					//var sex = $('input:radio[name="sex"]:checked').val();

					//发异步，把数据提交给golang后台
					$.ajax({
						type: "PUT",
						url: "/holiday/holiDate",
						contentType: "application/json; charset=utf-8",
						data: JSON.stringify({
							"id": id,
							"dateTime" : formData.holidayDate,
							"holiday": JSON.parse(formData.holiday),
							"holidayType": JSON.parse(formData.holidayType),
							"holidayName": formData.holidayName
						}),
						dataType: "json",
						success: function (data) {
							layer.open({
								content: "更新成功",
								btn: ["确定"],
								// icon: 6,
								btn1: function(index2, layero) {
									//获取提交成功的时间
									var time = new Date();
									var timeNow = util.toDateString(time);
									// 获得frame索引
									var index = parent.layer.getFrameIndex(window.name);
								
									// var _len = parent.$('#memberList tr').length;
									// console.log(parent.$('#memberList'))
									// alert(_len);
									// parent.$('#memberList').append(						
									// 	'<tr data-id="' + _len + '">' +
									// 		'<td>'+
									// 			'<div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="' + _len + '"><i class="layui-icon">&#xe605;</i></div>'+
									// 		'</td>'+
									// 		'<td>' + _len + '</td>'+
									// 		'<td>'+f.username+'</td>'+
									// 		'<td>'+f.sex+'</td>'+
									// 		'<td>'+f.phone+'</td>'+
									// 		'<td>'+f.email+'</td>'+
									// 		'<td>北京市西城区</td>'+
									// 		'<td>'+timeNow+'</td>'+
									// 		'<td class="td-status"><span class="layui-btn layui-btn-normal layui-btn-xs">已启用</span></td>'+
									// 		'<td class="td-manage">'+
									// 			'<a onclick="member_stop(this,\'10001\')" href="javascript:;" title="启用"><i class="layui-icon">&#xe601;</i></a>'+
									// 			'<a title="编辑" onclick="WeAdminShow(\'编辑\',\'./edit.html\',600,400)" href="javascript:;"><i class="layui-icon">&#xe642;</i></a>'+
									// 			'<a onclick="WeAdminShow(\'修改密码\',\'./password.html\',600,400)" title="修改密码" href="javascript:;"><i class="layui-icon">&#xe631;</i></a>'+
									// 			'<a title="删除" onclick="member_del(this,\'要删除的id\')" href="javascript:;"><i class="layui-icon">&#xe640;</i></a>'+
									// 		'</td>'+
									// 	'</tr>'	
									// );
									//关闭当前frame
									parent.layer.close(index);
									parent.location.reload();
								},
						});
						},
						error: function (data) {
							layer.open({
							content: "增加失败",
							btn: "确定",
							icon: 6,
							})
						}
					});
					
					
					return false;
				});

			});
		</script>
	</body>

</html>